package com.axter.libs.photo.choosephoto;

import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.axter.libs.base.adapter.IBaseViewHolder;
import com.axter.libs.photo.ImageLoaderCache;
import com.axter.libs.photo.R;
import com.axter.libs.photo.bean.MediaFolder;
import com.axter.libs.photo.widget.RectImageView;

/**
 * Created by zhaobo on 2016/10/14.
 */

public class ChoosePhotoFolderViewHolder implements IBaseViewHolder<MediaFolder> {
    ChoosePhotoFolderAdapter adapter;
    ImageView iv_thumb;
    ImageView iv_select;
    TextView tv_title;
    TextView tv_desc;

    public ChoosePhotoFolderViewHolder(ChoosePhotoFolderAdapter adapter) {
        this.adapter = adapter;
    }

    @Override
    public Object getContentView() {
        return R.layout.choosephoto_item_folder;
    }

    @Override
    public void bindViews(View view) {
        iv_thumb = (RectImageView) view.findViewById(R.id.iv_thumb);
        tv_title = (TextView) view.findViewById(R.id.tv_title);
        tv_desc = (TextView) view.findViewById(R.id.tv_desc);
        iv_select = (ImageView) view.findViewById(R.id.iv_select);
    }

    @Override
    public void handleData(MediaFolder folder, int position) {
        String title = "";
        String num = "";
        String path = "";
        if (folder != null) {
            title = folder.getTitle();
            if (folder.getImages() != null) {
                num = String.format(iv_thumb.getContext().getString(R.string.photoselect_unit_zhang), folder.size());
                if (folder.size() > 0) {
                    path = folder.getFolderThumb();
                }
            }
        }

        ImageLoaderCache.displayLocale(path, iv_thumb, 100, 100, R.drawable.choosephoto_imgbg);
        tv_title.setText(title);
        tv_desc.setText(num);
        if (adapter.currentSelectedPosition == position) {
            iv_select.setSelected(true);
        } else {
            iv_select.setSelected(false);
        }
    }
}
